//package com.wejoy.video.middle.station.admin.filter;
//
//import com.wejoy.video.middle.station.admin.util.CurrentUserUtils;
//import com.wejoy.video.middle.station.data.annotation.RoleCheck;
//import com.wejoy.video.middle.station.data.domain.system.SysResource;
//import com.wejoy.video.middle.station.data.domain.system.SysUser;
//import com.wejoy.video.middle.station.data.exception.BusinessException;
//import com.wejoy.video.middle.station.data.service.system.ISysRoleResourceService;
//import com.wejoy.video.middle.station.data.service.system.ISysRoleService;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.Signature;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import java.lang.reflect.Method;
//import java.util.ArrayList;
//import java.util.List;
//
//@Aspect
//@Component
//public class RoleCheckService {
//
//    protected Logger logger = LoggerFactory.getLogger(RoleCheckService.class);
//    @Autowired
//    private ISysRoleService sysRoleService;
//    @Autowired
//    private ISysRoleResourceService sysRoleResourceService;
//
//
//    //切入点表达式决定了用注解方式的方法切还是针对某个路径下的所有类和方法进行切，方法必须是返回void类型
//    @Pointcut("@annotation(com.wejoy.video.middle.station.data.annotation.RoleCheck)")
//    private void roleCheckCut() {};
//
//    //定义了切面的处理逻辑。即方法上加了@MyAnnotation注解，将会进行权限校验
//    @Around("roleCheckCut()")
//    public Object operateAuth(ProceedingJoinPoint pjp) throws Throwable {
//
//        //打印日志
//        Signature signature = pjp.getSignature();
//        String className = pjp.getTarget().getClass().getSimpleName();
//        String methodName = signature.getName();
//        logger.info("className:{},methodName:{}", className, methodName);
//        MethodSignature sign =  (MethodSignature)pjp.getSignature();
//        Method method = sign.getMethod();
//        RoleCheck annotation = method.getAnnotation(RoleCheck.class);
//        System.out.println(annotation.name());
//        //获取接口请求时header中的user_name参数，进行校验
//        SysUser sysUser = (SysUser) ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession().getAttribute(CurrentUserUtils.SYSTEM_USER);
//        List<String> sysResourceIdentityList = new ArrayList<>();
//        List<SysResource> sysResourceList = new ArrayList<>();
//        sysRoleResourceService.buildUserResourceListAndIdentityList(sysUser.getSysRoleList(),sysResourceList,sysResourceIdentityList);
//        String[] split = annotation.name().split(",");
//        Boolean flag = false;
//        for (int i = 0; i < split.length; i++) {
//            if(sysResourceIdentityList.contains(split[i])){
//               flag = true;
//            }
//        }
//        if(!flag){
//            throw new BusinessException("权限不足");
//        }
//        return pjp.proceed();
//    }
//}